//
//  YBCompleteProgressView.m
//  ZhongWangYuanApp
//
//  Created by apple on 18/6/4.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "YBCompleteProgressView.h"

#define TopGreen @"5bb85d"
#define TopOrange @"ffa016"

@interface YBCompleteProgressView ()
@property (nonatomic , strong) UIView * bgView;

@property (nonatomic , strong) UIView * progressView;

@property (nonatomic , strong) UILabel * titleLabel;

@property (nonatomic , strong) UILabel * completeLabel;
@end

@implementation YBCompleteProgressView

- (instancetype)initWithFrame:(CGRect)frame title:(NSString *)title
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initMyView];
        self.titleLabel.text = title;
    }
    return self;
}


-(void)initMyView{
    [self addSubview:self.titleLabel];
    [self addSubview:self.completeLabel];
    [self addSubview:self.bgView];
    [self addSubview:self.progressView];
}

-(void)setProgressWithTotal:(NSInteger)total completeNumber:(NSInteger)completeNumber
{
    self.completeLabel.text = [NSString stringWithFormat:@"已完成%ld门" , completeNumber];
    if (total == 0) {
        if (completeNumber == 0) {
            self.progressView.frame = CGRectMake(ItemWidth * 20, ItemHeight * 55, 0.01, ItemHeight * 40);
            self.progressView.backgroundColor = [UIColor zj_colorWithHexString:TopOrange];
        }
        else{
            self.progressView.frame = CGRectMake(ItemWidth * 20, ItemHeight * 55, ([UIScreen zj_screenWith] - ItemWidth * 40), ItemHeight * 40);
            self.progressView.backgroundColor = [UIColor zj_colorWithHexString:TopGreen];
        }
    }
    else{
        if (total <= completeNumber) {
            self.progressView.frame = CGRectMake(ItemWidth * 20, ItemHeight * 55, ([UIScreen zj_screenWith] - ItemWidth * 40), ItemHeight * 40);
            self.progressView.backgroundColor = [UIColor zj_colorWithHexString:TopGreen];
        }
        else{
            CGFloat proNumber = completeNumber / (total * 1.0);
            self.progressView.frame = CGRectMake(ItemWidth * 20, ItemHeight * 55, ([UIScreen zj_screenWith] - ItemWidth * 40) * proNumber, ItemHeight * 40);
            self.progressView.backgroundColor = [UIColor zj_colorWithHexString:TopOrange];
        }
    }
}


-(UILabel *)titleLabel
{
    if (!_titleLabel) {
        _titleLabel = [ToolClass creatLabelWithFrame:CGRectMake(ItemWidth * 20, 0, [UIScreen zj_screenWith] * 0.4 - 20 * ItemWidth, ItemHeight * 55) font:15 textColor:[UIColor textGrayColor] text:@""];
        _titleLabel.font = LYPBOLDFONT(15);
    }
    return _titleLabel;
}

-(UILabel *)completeLabel
{
    if (!_completeLabel) {
        _completeLabel = [ToolClass creatLabelWithFrame:CGRectMake([UIScreen zj_screenWith] * 0.4, 0, [UIScreen zj_screenWith] * 0.6 - 20 * ItemWidth, ItemHeight * 55) font:13 textColor:[UIColor textGrayColor] text:@"已完成0门"];
        _completeLabel.textAlignment = NSTextAlignmentRight;
    }
    return _completeLabel;
}


-(UIView *)bgView
{
    if (!_bgView) {
        _bgView = [[UIView alloc]initWithFrame:CGRectMake(ItemWidth * 20, ItemHeight * 55, [UIScreen zj_screenWith] - ItemWidth * 40, ItemHeight * 40)];
        _bgView.backgroundColor = [UIColor themeGrayColor];
        _bgView.layer.cornerRadius = ItemHeight * 20;
    }
    return _bgView;
}

-(UIView *)progressView
{
    if (!_progressView) {
        _progressView = [[UIView alloc]initWithFrame:CGRectMake(ItemWidth * 20, ItemHeight * 55, 0.01, ItemHeight * 40)];
        _progressView.backgroundColor = [UIColor zj_colorWithHexString:TopOrange];
        _progressView.layer.cornerRadius = ItemHeight * 20;
    }
    return _progressView;
}

@end
